package com.zzty.txj1.controller;

import com.zzty.txj1.entity.Ability;
import com.zzty.txj1.entity.User;
import com.zzty.txj1.service.AbilityService;
import com.zzty.txj1.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ranking")
public class RankingController {
    private static final Logger logger = LoggerFactory.getLogger(RankingController.class);

    @Autowired
    private UserService userService;
    @Autowired
    private AbilityService abilityService;
    @RequestMapping(value = "/getAbilityList/{clazzId}")
    public List<Ability> getAbilityList(@PathVariable("clazzId") Integer clazzId){
        logger.info("ranking--controller ============ getAbilityList");
        logger.info("ranking--controller clazzId ======="+clazzId);
       List<Ability> abilities=null;
        List<User> users=userService.getUserByClazzId(clazzId);
        logger.info("ranking--controller users ======="+users);
       for(User user:users){
           if(abilities==null){
               abilities=new ArrayList<Ability>();
           }
           Ability ability=abilityService.getAbilityByUserId(user);
           if(ability!=null){
               abilities.add(ability);
           }
           logger.info("ranking--controller ability ======="+ability);

       }
        logger.info("ranking--controller abilities ======="+abilities);
        return abilities;
    }
    @RequestMapping("/getUserById/{id}")
    public User getUserById(@PathVariable("id") Integer id){
        logger.info("ranking--controller ============ getUserById");
        logger.info("ranking--controller id ======="+id);
        User user=userService.getUserById(id);
        logger.info("ranking--controller user ======="+user);
        return user;
    }
}
